﻿using AutoMapper;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Logistics.Model;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Application.Services;

namespace Logistics.SignIn
{
    public class SignInAppService : ApplicationService, ISignInAppService
    {
        public readonly ISignInRepository _signInRepository;

        public SignInAppService(ISignInRepository signInRepository)
        {
            _signInRepository = signInRepository;
        }

        /// <summary>
        /// 登录方法
        /// </summary>
        /// <param name="accountNumber">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public async Task<int> PostSignEfInAsync(string accountNumber, string password)
        {
           var oper=await _signInRepository.SignInAsync(accountNumber, password);
           if (oper == null)
           {
               return 0;
           }

           var dto = ObjectMapper.Map<Operator, OperatorDto>(oper);
           return dto.Id;
        }


        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="accountNumber"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task<int> PutChangePassword(string accountNumber, string password)
        {
            int i =await _signInRepository.PutChangePassword(accountNumber, password);
            return i;
        }

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="mailbox"></param>
        public void SendMailbox(string mailbox)
        {
            _signInRepository.SendMailbox(mailbox);
        }

        /// <summary>
        /// 验证账号是否存在
        /// </summary>
        /// <param name="accountNumber"></param>
        /// <returns></returns>
        public async Task<int> VerifyAccountNumber(string accountNumber)
        {
            var i = await _signInRepository.VerifyAccountNumber(accountNumber);
            return i;
        }

    }
}
